home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / Ant Movie Catalog 3.5.0.2 / amc_install.exe / {app} / Scripts / dvdinfo (BE).ifs < prev    next >
Text File  |  2005-05-16  |  9KB  |  289 lines

  1. (***************************************************
  2.  
  3. Ant Movie Catalog importation script
  4. www.antp.be/software/moviecatalog/
  5.  
  6. [Infos]
  7. Authors=(c) 2005 tomba
  8. Title=dvdinfo.be
  9. Description=Movie description and picture from dvdinfo.be
  10. Site=http://www.dvdinfo.be
  11. Language=NL
  12. Version=1.1
  13. Requires=3.5.0
  14. Comments=Script written on Bad Omen's request.||Changes since v1.0:|- added SearchType option|
  15. License=This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.|
  16. GetInfo=1
  17.  
  18. [Options]
  19. SearchType=1|1|0=cat=14 (Zoek button)|1=cat=21 (Full reviews)
  20.  
  21. ***************************************************)
  22.  
  23. program dvdinfo;
  24. uses
  25.   StringUtils1;
  26. var
  27.   MovieName: string;
  28.   SearchType: Integer;
  29.  
  30. // simple string procedures
  31. function StringReplaceAll(S, Old, New: string): string;
  32. begin
  33.   while Pos(Old, S) > 0 do
  34.     S := StringReplace(S, Old, New);
  35.   Result := S;
  36. end;
  37.  
  38. procedure CutAfter(var Str: string; Pattern: string);
  39. begin
  40.   Str := Copy(str, Pos(Pattern, Str) + Length(Pattern), Length(Str));
  41. end;
  42. procedure CutBefore(var Str: string; Pattern: string);
  43. begin
  44.   Str := Copy(Str, Pos(Pattern, Str), Length(Str));
  45. end;
  46.  
  47. // Loads and analyses page from internet (list of movies or direct hit)
  48. procedure AnalyzePage(Address: string);
  49. var
  50.   Page: TStringList;
  51. begin
  52.   Page := TStringList.Create;
  53.   if SearchType = 1 then Page.Text := PostPage(Address,'keyword='+URLEncode(MovieName))
  54.   else Page.Text := GetPage(Address);
  55.   // movie list
  56.   if Pos('<tr><td class="spacer-tekst"></td><td class="content-tekst" height="25', Page.Text) > 0 then
  57.   begin
  58.     PickTreeClear;
  59.     PickTreeAdd('Search results:', '');
  60.     AddMoviesTitles(Page);
  61.     if PickTreeExec(Address) then
  62.       AnalyzeMoviePage(Address);
  63.   end
  64.   else ShowMessage('Nothing found');
  65. end;
  66.  
  67. // Extracts movie details from page
  68. procedure AnalyzeMoviePage(Address: string);
  69. var
  70.   Page: string;
  71.   Value: string;
  72.   Title: string;
  73.   Review: string;
  74.   Tmp: string;
  75.   Comments: string;
  76.   WasActors: integer;
  77. begin
  78.   Address := 'http://dvdinfo.be/' + Address;
  79.   Page := GetPage(Address);
  80.  
  81.   // original title
  82.   Value := GetStringFromHTML(Page, '<td class="content-header" colspan="3">BESPREKING', ': ', ' (',0);
  83.   if Length(Value) > 0 then
  84.   begin
  85.     SetField(fieldOriginalTitle, Value);
  86.   end;
  87.  
  88.   Tmp := Page;
  89.   // regio
  90.   CutBefore(Tmp, '<td class="content-specs"');
  91.   CutAfter(Tmp, '</td>');
  92.   // genre
  93.   CutBefore(Tmp, '<td class="content-specs"');
  94.   Value := GetStringFromHTML(Tmp, '<td class="content-specs"', '>', '</td>', 0);
  95.   SetField(fieldCategory, Value);
  96.   CutAfter(Tmp, '</td>');
  97.   // versie (version)
  98.   CutBefore(Tmp, '<td class="content-specs"');
  99.   CutAfter(Tmp, '</td>');
  100.   // jaar (year)
  101.   CutBefore(Tmp, '<td class="content-specs"');
  102.   Value := GetStringFromHTML(Tmp, '<td class="content-specs"', '>', '</td>', 0);
  103.   SetField(fieldYear, Value);
  104.   CutAfter(Tmp, '</td>');
  105.   // leeftijd (rating for minimum age)
  106.   CutBefore(Tmp, '<td class="content-specs"');
  107.   CutAfter(Tmp, '</td>');
  108.   // speelduur (runtime)
  109.   CutBefore(Tmp, '<td class="content-specs"');
  110.   Value := GetStringFromHTML(Tmp, '<td class="content-specs"', '>', ' min.</td>', 0);
  111.   SetField(fieldLength, Value);
  112.   CutAfter(Tmp, '</td>');
  113.   // Ondertitels (subtitles)
  114.   CutBefore(Tmp, '<td class="content-specs"');
  115.   Value := GetStringFromHTML(Tmp, '<td class="content-specs"', '>', '</td>', 0);
  116.   SetField(fieldSubtitles, Value);
  117.   CutAfter(Tmp, '</td>');
  118.   // Type dvd
  119.   CutBefore(Tmp, '<td class="content-specs"');
  120.   CutAfter(Tmp, '</td>');
  121.  
  122.   //URL
  123.   SetField(fieldURL,Address);
  124.  
  125.   // Image
  126.   Value := GetStringFromHTML(Page, '<td class="content-tekst"><center><img src="images/reviews', '/', '.jpg"', 0);
  127.   Value := 'http://dvdinfo.be/images/' + Value + '.jpg';
  128.   GetPicture(Value);
  129.  
  130.   // Description
  131.   Value := GetStringFromHTML(Page, '<td class="content-tekst" colspan="3">', '', '<td class="spacer-tekst"></td>',1);
  132.   if Length(Value) > 0 then SetField(fieldDescription, Value);
  133.  
  134.   // Director
  135.   Value := GetStringFromHTML(Page, '<b>Regisseur:', ' </b>', '<br>', 0);
  136.   SetField(fieldDirector, Value);
  137.  
  138.   // Actors
  139.   Value := GetStringFromHTML(Page, '<b>Met:', ' </b>', '<br>', 0);
  140.   SetField(fieldActors, Value);
  141.  
  142.   // Rating
  143.   Value := GetStringFromHTML(Page, '<b>Film:', ' </b>', '/10<br>', 0);
  144.   SetField(fieldRating, Value);
  145.  
  146.   //DisplayResults;
  147. end;
  148.  
  149. // Adds movie titles from search results to tree
  150. procedure AddMoviesTitles(ResultsPage: TStringList);
  151. var
  152.   Page: string;
  153.   MovieTitle, MovieAddress: string;
  154. begin
  155.   Page := ResultsPage.Text;
  156.  
  157.   while Pos('<tr><td class="spacer-tekst"></td><td class="content-tekst" height="25"', Page) > 0 do
  158.   begin
  159.     CutBefore(Page, '<tr><td class="spacer-tekst"></td><td class="content-tekst" height="25"');
  160.     MovieAddress := GetStringFromHTML(Page, '><a ', 'href="', '">', 0);
  161.     MovieTitle := GetStringFromHTML(Page, 'a href', '">', '</a>', 0);
  162. //    ShowMessage('MA='+MovieAddress+#10#13+'MT='+MovieTitle);
  163.     CutAfter(Page, '</td></tr>');
  164.     PickTreeAdd(MovieTitle, MovieAddress);
  165.   end;
  166. end;
  167.  
  168. // Extracts single movie detail (like director, genre) from page
  169. function GetStringFromHTML(Page, StartTag, CutTag, EndTag: string; RemoveTags: Integer): string;
  170. begin
  171.   Result := '';
  172.   // recognition tag - if present, extract detail from page, otherwise assume detail is not present
  173.   if Pos(StartTag, Page) > 0 then begin
  174.     CutBefore(Page, StartTag);
  175.     // optional cut tag helps finding right string in html page
  176.     if Length(CutTag) > 0 then
  177.       CutAfter(Page, CutTag);
  178.     // movie detail copied with html tags up to end string
  179.     Result := Copy(Page, 0, Pos(EndTag, Page) - 1);
  180.     // remove html tags (if needed) and decode html string
  181.     if RemoveTags > 0 then
  182.     begin
  183.       HTMLRemoveTags(Result);
  184.     end;
  185.     HTMLDecode(Result);
  186. //  ShowMessage('DEBUG: GetStringFromHTML - StartTag "'+StartTag+'", CutTag "'+CutTag+'", EndTag "'+EndTag+'", Result "'+Result+'" ___ '+Page);
  187.   end;
  188. end;
  189.  
  190.  
  191. function GetToken(aString, SepChar: String; TokenNum: Integer):String;
  192. var
  193.    Token     : string;
  194.    StrLen    : Integer;
  195.    TNum      : Integer;
  196.    TEnd      : Integer;
  197.  
  198. begin
  199.      StrLen := Length(aString);
  200.      TNum   := 1;
  201.      TEnd   := StrLen;
  202.      while ((TNum <= TokenNum) and (TEnd <> 0)) do
  203.      begin
  204.           TEnd := Pos(SepChar,aString);
  205.           if TEnd <> 0 then
  206.           begin
  207.                Token := Copy(aString,1,TEnd-1);
  208.                Delete(aString,1,TEnd);
  209.                TNum := TNum + 1;
  210.           end
  211.           else
  212.           begin
  213.                Token := aString;
  214.           end;
  215.      end;
  216.      if TNum >= TokenNum then
  217.      begin
  218.           GetToken := Token;
  219.      end
  220.      else
  221.      begin
  222.           GetToken := '';
  223.      end;
  224. end;
  225.  
  226. function AsinParse(Line : string): string;
  227. begin
  228.   Result := GetToken(GetToken(Line,'.',2),Chr(34),1);
  229. end;
  230.  
  231. procedure RemovePronoun(var Str: string);
  232. var
  233.   i: Integer;
  234.   s: string;
  235.   c: char;
  236. begin
  237.   // remove pronouns
  238.   if (Copy(Str, 0, 2) = 'L ') or (Copy(Str, 0, 2) = 'A ') then
  239.     Str := Copy(Str, 3, Length(Str) - 2)
  240.   else if (Copy(Str, 0, 3) = 'Le ') or (Copy(Str, 0, 3) = 'La ') or (Copy(Str, 0, 3) = 'Un ') then
  241.     Str := Copy(Str, 4, Length(Str) - 3)
  242.   else if (Copy(Str, 0, 4) = 'Les ') or (Copy(Str, 0, 4) = 'Une ') or (Copy(Str, 0, 4) = 'The ') then
  243.     Str := Copy(Str, 5, Length(Str) - 4);
  244.  
  245.   Str := StringReplaceAll(Str, '_', ' ');
  246.   // remove non-letters, non-digits and non-spaces
  247.   // polish diacritics chars are allowed
  248.   s := '';
  249.   for i := 1 to Length(Str) do begin
  250.   c := StrGet(Str, i);
  251.     if ((c<'a') or (c>'z')) and
  252.        ((c<'A') or (c>'Z')) and
  253.        ((c<'0') or (c>'9')) and
  254.        (c<>' ') and (c<>'╣') and
  255.        (c<>'Ñ') and (c<>'Ω') and
  256.        (c<>'╩') and (c<>'µ') and
  257.        (c<>'╞') and (c<>'£') and
  258.        (c<>'î') and (c<>'┐') and
  259.        (c<>'»') and (c<>'ƒ') and
  260.        (c<>'Å') and (c<>'≤') and
  261.        (c<>'╙') and (c<>'│') and
  262.        (c<>'ú') and (c<>'±') and
  263.        (c<>'╤') then
  264.     else
  265.       s := s + Copy(Str, i, 1);
  266.   end;
  267.   Str := s;
  268. end;
  269.  
  270. begin
  271.   if CheckVersion(3,5,0) then begin
  272.     SearchType := GetOption('SearchType');
  273.     MovieName := GetField(fieldOriginalTitle);
  274.     if MovieName = '' then MovieName := GetField(fieldTranslatedTitle);
  275.     RemovePronoun(MovieName);
  276.     if Input('dvdinfo.be import', 'Enter movie title:', MovieName) then
  277.       case SearchType of
  278.         0 :
  279.         begin
  280.           AnalyzePage('http://dvdinfo.be/index-02.php?cat=14');
  281.         end;
  282.         1 :
  283.         begin
  284.           AnalyzePage('http://dvdinfo.be/index-02.php?cat=21&kerword='+URLEncode(MovieName)+'&full=Review');
  285.         end;
  286.       end;
  287.   end else ShowMessage('AMC version required: 3.5.0');
  288. end.
  289.